Java Basics: Rapid Review by Akila Goel

Java Basics: Rapid Review by Akila Goel

Author:Akila Goel
Language: eng
Format: azw3
Publisher: UNKNOWN
Published: 2017-08-17T07:00:00+00:00


Switch statements have a number of possible scenarios that can occur, based on the certain condition.

However, they only work with variables of type char, String, short, byte, and int.

Switch statement syntax:

switch(variable)

{

case 1: check variable;

Statements;

break;

case 2: check variable;

Statements;

break;

case 3: check variable;

Statements;

break;

default: statement;

}

Switch Statement Example:

char LetterGrade = ‘A’;

switch(LetterGrade)

{

case 'A' :

System.out.println("Awesome!");

break;

case 'B' :

System.out.println("Brilliant!");

break;

case 'C' :

System.out.println("Cool");

break;

case 'D' :

System.out.println("Definitely could improve");

break;

case 'F' :

System.out.println("Failed. Try Again.");

break;

default :

System.out.println("Not a valid grade");

}



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.